//
//  BDSSpeechSynthesizerDelegate.h
//  BDSSpeechSynthesizer
//
//  Created by  段弘 on 13-11-23.
//  Copyright (c) 2013年 百度. All rights reserved.
//

#import <Foundation/Foundation.h>
@class BDSSpeechSynthesizer;

typedef enum BDSAudioPlayerPauseSources
{
    BDS_AUDIO_PLAYER_PAUSE_SOURCE_USER,
    BDS_AUDIO_PLAYER_PAUSE_SOURCE_AUDIO_INTERRUPT,
    BDS_AUDIO_PLAYER_PAUSE_SOURCE_ENTERED_BACKGROUND
}BDSAudioPlayerPauseSources;

typedef enum BDSAudioFormat{
    BDS_AUDIO_FORMAT_PCM_16K = 1,
    BDS_AUDIO_FORMAT_MP3 = 2
}BDSAudioFormat;

@protocol BDSSpeechSynthesizerDelegate <NSObject>

/**
 * @brief 合成器开始工作
 *
 * @param speechSynthesizer 合成器对象
 */
@optional
/**
 * @brief Began synthesizing new sentence.
 *        NOTE: Will receive one call for each sentenceNumber
 *        when using batchSpeak/batchSynthesize.
 *
 * @param speechSynthesizer 合成器对象
 * @param SynthesizeSentence Index of string in strings array passed to
 *          -(int)batchSynthesize:(NSArray *)strings; or - (int)batchSpeak:(NSArray*)strings;
 *        always 0 if synthesis was started by using
 *          - (int)synthesize:(NSString *)text; or - (int)speak:(NSString *)text;
 */
- (void)synthesizerStartWorkingSentence:(BDSSpeechSynthesizer *)speechSynthesizer
                         sentenceNumber:(NSInteger)SynthesizeSentence;

/**
 * @brief Finished synthesizing a sentence.
 *        NOTE: Will receive one call for each sentenceNumber
 *        when using batchSpeak/batchSynthesize.
 *
 * @param speechSynthesizer 合成器对象
 * @param SynthesizeSentence Index of string in strings array passed to
 *          -(int)batchSynthesize:(NSArray *)strings; or - (int)batchSpeak:(NSArray*)strings;
 *        always 0 if synthesis was started by using
 *          - (int)synthesize:(NSString *)text; or - (int)speak:(NSString *)text;
 */
- (void)synthesizerFinishWorkingSentence:(BDSSpeechSynthesizer *)speechSynthesizer
                          sentenceNumber:(NSInteger)SynthesizeSentence;

/**
 * @brief Began speak a sentence.
 *        NOTE: Will receive one call for each sentenceNumber
 *        when using batchSpeak.
 *        Not called if only synthesizing (synthesis started by
 *          - (int)synthesize:(NSString *)text; or -(int)batchSynthesize:(NSArray *)strings;)
 *
 * @param speechSynthesizer 合成器对象
 * @param SpeakSentence The index of sentence that was started.
 *        Index of string in strings array passed to
 *          - (int)batchSpeak:(NSArray*)strings;
 *        always 0 if synthesis was started by using
 *          - (int)speak:(NSString *)text;
 */
- (void)synthesizerSpeechStartSentence:(BDSSpeechSynthesizer *)speechSynthesizer
                        sentenceNumber:(NSInteger)SpeakSentence;

/**
 * @brief 朗读完成
 *        NOTE: Will receive one call for each sentenceNumber
 *        when using batchSpeak.
 *        Use sentenceNumber to determine if all finished.
 *        Not called if only synthesizing (synthesis started by
 *          - (int)synthesize:(NSString *)text; or -(int)batchSynthesize:(NSArray *)strings;)
 *
 * @param speechSynthesizer 合成器对象
 * @param SpeakSentence Finished speaking sentence. Index of string in strings array passed to
 *          - (int)batchSpeak:(NSArray*)strings;
 *        always 0 if synthesis was started by using
 *          - (int)speak:(NSString *)text;
 */
- (void)synthesizerSpeechEndSentence:(BDSSpeechSynthesizer *)speechSynthesizer
                      sentenceNumber:(NSInteger)SpeakSentence;

/**
 * @brief 新的语音数据已经合成
 *
 * @param speechSynthesizer 合成器对象
 * @param newData 语音数据
 * @param fmt Audio format in passed buffer.
 * @param newLength Currently synthesized character count of current sentence
 *        to get total character count, you must add lengths of all sentences
 *        up to sentence-1，取值范围[0, [text length]]
 * @param SynthesizeSentence the sentence to which this data belongs to. Indicates index in
 *        strings array passed to
 *          -(int)batchSynthesize:(NSArray *)strings; or - (int)batchSpeak:(NSArray*)strings;
 *        always 0 if synthesis was started by using
 *          - (int)synthesize:(NSString *)text; or - (int)speak:(NSString *)text;
 */
- (void)synthesizerNewDataArrived:(BDSSpeechSynthesizer *)speechSynthesizer
                             data:(NSData *)newData
                       DataFormat:(BDSAudioFormat)fmt
                       characterCount:(int)newLength
                   sentenceNumber:(NSInteger)SynthesizeSentence;

/**
 * @brief Gives an estimation about how many characters have been spoken so far.
 *        Not called if only synthesizing (synthesis started by
 *          - (int)synthesize:(NSString *)text; or -(int)batchSynthesize:(NSArray *)strings;)
 *
 * @param speechSynthesizer 合成器对象
 * @param length Currently finished speaking character count of current sentence
 *        to get total character count, you must add lengths of all sentences
 *        up to sentence-1，取值范围[0, [text length]]
 * @param SpeakSentence Index of string in strings array passed to
 *          - (int)batchSpeak:(NSArray*)strings;
 *        always 0 if synthesis was started by using
 *          - (int)speak:(NSString *)text;
 */
- (void)synthesizerTextSpeakLengthChanged:(BDSSpeechSynthesizer *)speechSynthesizer
                           characterCount:(int)newLength
                           sentenceNumber:(NSInteger)SpeakSentence;

/**
 * @brief invoked when player gets paused
 * @param speechSynthesizer 合成器对象
 * @param src, what caused the pause.
 */
- (void)synthesizerPaused:(BDSSpeechSynthesizer *)speechSynthesizer
              source:(BDSAudioPlayerPauseSources)src;

/**
 * @brief invoked when player is resumed from pause
 * @param speechSynthesizer 合成器对象
 */
- (void)synthesizerResumed:(BDSSpeechSynthesizer *)speechSynthesizer;

/**
 * @brief 合成器发生错误
 *
 * @param speechSynthesizer 合成器对象
 * @param error 错误对象
 * @param SpeakSentence Currently speaking sentence. Index of string in strings array passed to
 *          - (int)batchSpeak:(NSArray*)strings;
 *        always 0 if synthesis was started by using
 *          - (int)speak:(NSString *)text;
 *        always -1 if synthesis was started by
 *          - (int)synthesize:(NSString *)text; or -(int)batchSynthesize:(NSArray *)strings;
 *
 * @param SynthesizeSentence Currently synthesizing sentence. Index of string in strings array passed to
 *          -(int)batchSynthesize:(NSArray *)strings; or - (int)batchSpeak:(NSArray*)strings;
 *        always 0 if synthesis was started by using
 *          - (int)synthesize:(NSString *)text; or - (int)speak:(NSString *)text;
 */
- (void)synthesizerErrorOccurred:(BDSSpeechSynthesizer *)speechSynthesizer
                           error:(NSError *)error
                        speaking:(NSInteger)SpeakSentence
                    synthesizing:(NSInteger)SynthesizeSentence;

@end